#include "filterdialog.h"
// TODO Put everything in schema structures

FilterDialog::FilterDialog( QString filter,
                            QMap<QString, QStringList> albums_attrs,
                            QMap<int,int> asc_indicies,
                            QMap<int,int> desc_indicies)
{
setupUi(this);
expTextEdit = new TextEdit(sql_tab);
expTextEdit->setObjectName(QString::fromUtf8("expTextEdit"));
expTextEdit->setEnabled(true);
expTextEdit->setAcceptRichText(false);

opened_album_attrs = albums_attrs;
QDate one_year_ago = QDate::currentDate().addYears(-1);
dateDateEdit->setDate(one_year_ago);
nomRecComboBox->addItems( opened_album_attrs.value("denominations") );
nomRecComboBox->setCurrentIndex(-1);
stateRecComboBox->addItems( opened_album_attrs.value("states") );
stateRecComboBox->setCurrentIndex(-1);
epochRecComboBox->addItems( opened_album_attrs.value("epochs") );
epochRecComboBox->setCurrentIndex(-1);
edgeIDRecComboBox->addItems( opened_album_attrs.value("edgeids") );
edgeIDRecComboBox->setCurrentIndex(-1);
materialRecComboBox->addItems( opened_album_attrs.value("materials") );
materialRecComboBox->setCurrentIndex(-1);
typeRecComboBox->addItems( opened_album_attrs.value("types") );
typeRecComboBox->setCurrentIndex(-1);
undertypeRecComboBox->addItems( opened_album_attrs.value("undertypes") );
undertypeRecComboBox->setCurrentIndex(-1);
mintRecComboBox->addItems( opened_album_attrs.value("mints") );
mintRecComboBox->setCurrentIndex(-1);
obvSymbolRecComboBox->addItems( opened_album_attrs.value("obvsymbs") );
obvSymbolRecComboBox->setCurrentIndex(-1);
revSymbolRecComboBox->addItems( opened_album_attrs.value("revsymbs") );
revSymbolRecComboBox->setCurrentIndex(-1);
obvTypeRecComboBox->addItems( opened_album_attrs.value("obvtypes") );
obvTypeRecComboBox->setCurrentIndex(-1);
revTypeRecComboBox->addItems( opened_album_attrs.value("revtypes") );
revTypeRecComboBox->setCurrentIndex(-1);
statusRecComboBox->addItems( opened_album_attrs.value("statuses") );
statusRecComboBox->setCurrentIndex(-1);
conditionRecComboBox->addItems( opened_album_attrs.value("conditions") );
conditionRecComboBox->setCurrentIndex(-1);
rectypeRecComboBox->addItems( opened_album_attrs.value("rectypes") );
rectypeRecComboBox->setCurrentIndex(-1);

    vboxLayout3->addWidget(expTextEdit);
    if (true != filter.isEmpty() )
    {
    set_basic(true);
    expTextEdit->setPlainText(filter);
    tabWidget->setCurrentIndex(4);
    }
    else
    {
    expTextEdit->setDisabled(true);
    expCheckBox->setChecked(false);
    }

QPixmap i_pixmap = QPixmap(":/binary/indexed.png");
QPixmap empty_pixmap = QPixmap(":/binary/empty-16.png");

QMap<QLabel *,QString> labels_map;
labels_map[nomLabel] = QString(QLatin1String("DENOMINATION"))  ;
labels_map[year1Label] = QString(QLatin1String("OBJ_YEAR"));
labels_map[year2Label] = QString(QLatin1String("OBJ_YEAR"));
labels_map[marksLabel] = QString(QLatin1String("MARKS"));
labels_map[stateLabel] = QString(QLatin1String("STATE"));
labels_map[epochLabel] = QString(QLatin1String("EPOCH"));
labels_map[materialLabel] = QString(QLatin1String("MATERIAL"));
labels_map[weightLabel] = QString(QLatin1String("WEIGHT"));
labels_map[valueLabel] = QString(QLatin1String("ACT_VALUE"));
labels_map[sellerLabel] = QString(QLatin1String("SELLER"));
labels_map[customerLabel] = QString(QLatin1String("CUSTOMER"));
labels_map[soldDateLabel] = QString(QLatin1String("SOLD_DATE"));
labels_map[statusLabel] = QString(QLatin1String("STATUS"));
labels_map[diamLabel] = QString(QLatin1String("DIAM"));
labels_map[edgeIDLabel] = QString(QLatin1String("EDGEID"));
labels_map[typeLabel] = QString(QLatin1String("OBJ_TYPE"));
labels_map[undertypeLabel] = QString(QLatin1String("OBJ_UNDERTYPE"));
labels_map[edgeLegendLabel] = QString(QLatin1String("EDGE_LEGEND"));
labels_map[obvArtistLabel] = QString(QLatin1String("OBVERSEARTIST"));
labels_map[revArtistLabel] = QString(QLatin1String("REVERSEARTIST"));
labels_map[obvEngraverLabel] = QString(QLatin1String("OBVERSEENGRAVER"));
labels_map[revEngraverLabel] = QString(QLatin1String("REVERSEENGRAVER"));
labels_map[issuerLabel] = QString(QLatin1String("ISSUER"));
labels_map[authorityLabel] = QString(QLatin1String("AUTHORITY"));
labels_map[mintLabel] = QString(QLatin1String("MINT"));
labels_map[mintageLabel] = QString(QLatin1String("MINTAGE"));
labels_map[obvSymbolLabel] = QString(QLatin1String("OBVERSESYMBOL"));
labels_map[obvTypeLabel] = QString(QLatin1String("OBVERSETYPE"));
labels_map[obvLegend1Label] = QString(QLatin1String("OBVERSELEGEND1"));
labels_map[obvLegen2Label] = QString(QLatin1String("OBVERSELEGEND2"));
labels_map[obvMarkLabel] = QString(QLatin1String("OBVERSECOUNTERMARK"));
labels_map[revSymbolLabel] = QString(QLatin1String("REVERSESYMBOL"));
labels_map[revTypeLabel] = QString(QLatin1String("REVERSETYPE"));
labels_map[revLegend1Label] = QString(QLatin1String("REVERSELEGEND1"));
labels_map[revLegend2Label] = QString(QLatin1String("REVERSELEGEND2"));
labels_map[revMarkLabel] = QString(QLatin1String("REVERSECOUNTERMARK"));
labels_map[conditionLabel] = QString(QLatin1String("CONDITION"));
labels_map[recordTypeLabel] = QString(QLatin1String("RECORDTYPE"));
labels_map[fromLabel] = QString(QLatin1String("FROMDATE"));
labels_map[toLabel] = QString(QLatin1String("TODATE"));
labels_map[dateObjLabel] = QString(QLatin1String("DATEONOBJECT"));
labels_map[eraObjLabel] = QString(QLatin1String("ERAONOBJECT"));
labels_map[rulerObjLabel] = QString(QLatin1String("RULERONOBJECT"));
labels_map[regionLabel] = QString(QLatin1String("REGION"));
labels_map[fsLabel] = QString(QLatin1String("FINDSPOT"));
labels_map[coordLabel] = QString(QLatin1String("COORDINATES"));
labels_map[latitude1Label] = QString(QLatin1String("LATITUDE"));
labels_map[latitude2Label] = QString(QLatin1String("LATITUDE"));
labels_map[longitude1Label] = QString(QLatin1String("LONGITUDE"));
labels_map[longitude2Label] = QString(QLatin1String("LONGITUDE"));

Schema * schema = new Schema;
    if (schema != NULL)
    {
    QMap<QString, int> columns_map = schema->columns_map();
    QMapIterator<QLabel *,QString> labels_map_i(labels_map);        
        while ( true == labels_map_i.hasNext() )
        {
        labels_map_i.next();
        QLabel * p = NULL;
        p = qobject_cast<QLabel *>( labels_map_i.key() );
            if ( NULL != p)
            {
                if (asc_indicies.value( columns_map.value( labels_map_i.value() ) ) == 1 &&
                    desc_indicies.value( columns_map.value( labels_map_i.value() ) ) == 1)
                {
                p->setPixmap(i_pixmap);
                }
                else
                {
                p->setPixmap(empty_pixmap);
                }
            }
        }
    }

QStringList column_names_list;
QMap<int, QString> column_names = schema->column_names();
    for ( int i = 0; i < column_names.size(); ++i )
    {
    column_names_list << column_names.value(i);
    }

QCompleter * completer = new QCompleter(column_names_list, this);

expTextEdit->setCompleter(completer);

delete schema;

QObject::connect(expCheckBox,
                 SIGNAL(toggled(bool)),
                 this,
                 SLOT(set_basic(bool)));

}

FilterDialog::~FilterDialog()
{
}

QString FilterDialog::return_filter()
{
bool case_insens = caseCheckBox->isChecked();

QString filter;
    if (true == expCheckBox->isChecked() )
    {
    filter = expTextEdit->toPlainText();
    return filter;
    }

    if ( true == nomCheckBox->isChecked() )
    {
        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }
    filter.append( QLatin1String("denomination") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == nomComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( nomRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == nomComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( nomRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == year1CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }
    filter.append( QLatin1String("obj_year ") );
    filter.append( year1ComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( year1SpinBox->value() ) );
    }

    if ( true == year2CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String(" and ") );
        }
    filter.append( QLatin1String("obj_year ") );
    filter.append( year2ComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( year2SpinBox->value() ) );
    }

    if ( true == marksCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("marks") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == marksComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( marksLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == marksComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( marksLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == stateCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("state") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == stateComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( stateRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == stateComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( stateRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == epochCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("epoch") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == epochComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( epochRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == epochComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( epochRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == materialCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("material") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == materialComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( materialRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == materialComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( materialRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == weightCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }
    filter.append( QLatin1String("weight ") );
    filter.append( weightComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( weightDoubleSpinBox->value() ) );
    }

    if ( true == estimCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }
    filter.append( QLatin1String("act_value ") );
    filter.append( estimComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( estimDoubleSpinBox->value() ) );
    }

    if ( true == sellerCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("seller") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == sellerComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( sellerRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == sellerComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( sellerRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == customerCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("customer") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == customerComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( customerRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == customerComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( customerRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == dateCheckBox->isChecked() )
    {
    QDate d = dateDateEdit->date();
    QString d_string = d.toString("yyyyMMdd");
        if ( true != filter.isEmpty() )
        {
        filter.append( QLatin1String(" and ") );
        }
    filter.append( QLatin1String("sold_date") );
        if ( QLatin1String("=") == dateComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
        filter.append( d_string );
        filter.append( QLatin1String(" ") );
        }
        else if ( QLatin1String(">=") == dateComboBox->currentText() )
        {
        filter.append( QLatin1String(" >= ") );
        filter.append( d_string );
        filter.append( QLatin1String(" ") );
        }
        else if ( QLatin1String("<=") == dateComboBox->currentText() )
        {
        filter.append( QLatin1String(" <= ") );
        filter.append( d_string );
        filter.append( QLatin1String(" ") );
        }
    }

    if ( true == mintCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("mint") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == mintComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( mintRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == mintComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( mintRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == statusCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("status") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == statusComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( statusRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == statusComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( statusRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == diamCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }
    filter.append( QLatin1String("diam ") );
    filter.append( diamComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( diamDoubleSpinBox->value() ) );    
    }

    if ( true == edgeIDCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("edgeid") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == edgeIDComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( edgeIDRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == edgeIDComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( edgeIDRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == typeCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obj_type") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == typeComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( typeRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == typeComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( typeRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == undertypeCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obj_undertype") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == undertypeComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( undertypeRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == undertypeComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( undertypeRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == edgeLegendCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("edge_legend") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == edgeLegendComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( edgeLegendLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == edgeLegendComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( edgeLegendLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == artistObvCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obverseartist") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == artistObvComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( artistObvLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == artistObvComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( artistObvLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == artistRevCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("reverseartist") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == artistRevComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( artistRevLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == artistRevComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( artistRevLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == engraverObvCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obverseengraver") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == engraverObvComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( engraverObvLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == engraverObvComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( engraverObvLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == engraverRevCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("reverseengraver") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == engraverRevComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( engraverRevLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == engraverRevComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( engraverRevLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == issuerCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("issuer") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == issuerComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( issuerLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == issuerComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( issuerLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == authCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("authority") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == authComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( authLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == authComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( authLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == mintageCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String(" and ") );
        }
    filter.append( QLatin1String("mintage ") );
    filter.append( mintageComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( mintageSpinBox->value() ) );
    }

    if ( true == obvSymbolCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obversesymbol") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == obvSymbolComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( obvSymbolRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == obvSymbolComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( obvSymbolRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == obvTypeCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obversetype") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == obvTypeComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( obvTypeRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == obvTypeComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( obvTypeRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == obvLegend1CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obverselegend1") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == obvLegend1ComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( obvLegend1LineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == obvLegend1ComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( obvLegend1LineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == obvLegend2CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obverselegend2") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == obvLegend2ComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( obvLegend2LineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == obvLegend2ComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( obvLegend2LineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == obvMarkCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("obversecountermark") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == obvMarkComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( obvMarkLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == obvMarkComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( obvMarkLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == revSymbolCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("reversesymbol") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == revSymbolComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( revSymbolRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == revSymbolComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( revSymbolRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == revTypeCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("reversetype") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == revTypeComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( revTypeRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == revTypeComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( revTypeRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == revLegend1CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("reverselegend1") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == revLegend1ComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( revLegend1LineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == revLegend1ComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( revLegend1LineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == revLegend2CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("reverselegend2") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == revLegend2ComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( revLegend2LineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == revLegend2ComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( revLegend2LineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == revMarkCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("reversecountermark") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == revMarkComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( revMarkLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == revMarkComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( revMarkLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == conditionCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("condition") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == conditionComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( conditionRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == conditionComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( conditionRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == rectypeCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("recordtype") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == rectypeComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( rectypeRecComboBox->currentText() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == rectypeComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( rectypeRecComboBox->currentText() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == toCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("todate") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == toComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( toLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == toComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( toLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == fromCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("fromdate") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == fromComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( fromLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == fromComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( fromLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == dateObjCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("dateonobject") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == dateObjComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( dateObjLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == dateObjComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( dateObjLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == eraObjCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("eraonobject") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == eraObjComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( eraObjLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == eraObjComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( eraObjLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == rulerObjCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("ruleronobject") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == rulerObjComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( rulerObjLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == rulerObjComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( rulerObjLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == regionCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("region") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == regionComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( regionLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == regionComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( regionLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == fsCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("findspot") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == fsComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( fsLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == fsComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( fsLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == coordCheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }

        if ( true == case_insens )
        {
        filter.append( QLatin1String("upper(") );
        }

    filter.append( QLatin1String("coordinates") );
        if ( true == case_insens )
        {
        filter.append( QLatin1String(")") );
        }

        if ( QLatin1String("~=") == coordComboBox->currentText() )
        {
        filter.append( QLatin1String(" like ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'\%") );
        filter.append( coordLineEdit->text() );
        filter.append( QLatin1String("\%\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else if ( QLatin1String("=") == coordComboBox->currentText() )
        {
        filter.append( QLatin1String(" = ") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String("upper(") );
            }
        filter.append( QLatin1String("\'") );
        filter.append( coordLineEdit->text() );
        filter.append( QLatin1String("\'") );
            if ( true == case_insens )
            {
            filter.append( QLatin1String(")") );
            }
        }
        else
        {
        }
    }

    if ( true == latitude1CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }
    filter.append( QLatin1String("latitude ") );
    filter.append( latitude1ComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( latitude1SpinBox->value() ) );
    }

    if ( true == longitude1CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }
    filter.append( QLatin1String("longitude ") );
    filter.append( longitude1ComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( longitude1SpinBox->value() ) );
    }

    if ( true == latitude2CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }
    filter.append( QLatin1String("latitude ") );
    filter.append( latitude2ComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( latitude2SpinBox->value() ) );
    }

    if ( true == longitude2CheckBox->isChecked() )
    {
        if (true != filter.isEmpty() )
        {
        filter.append( QLatin1String("\nand\n") );
        }
    filter.append( QLatin1String("longitude ") );
    filter.append( longitude2ComboBox->currentText() );
    filter.append( QLatin1String(" ") );
    filter.append( QString::number( longitude2SpinBox->value() ) );
    }

return filter;
}

void FilterDialog::set_basic(bool t)
{
caseCheckBox->setDisabled(t);
nomCheckBox->setDisabled(t);
year1CheckBox->setDisabled(t);
year2CheckBox->setDisabled(t);
marksCheckBox->setDisabled(t);
stateCheckBox->setDisabled(t);
epochCheckBox->setDisabled(t);
materialCheckBox->setDisabled(t);
weightCheckBox->setDisabled(t);
estimCheckBox->setDisabled(t);
sellerCheckBox->setDisabled(t);
customerCheckBox->setDisabled(t);
dateCheckBox->setDisabled(t);
mintCheckBox->setDisabled(t);
statusCheckBox->setDisabled(t);
diamCheckBox->setDisabled(t);
edgeIDCheckBox->setDisabled(t);
typeCheckBox->setDisabled(t);
undertypeCheckBox->setDisabled(t);
edgeLegendCheckBox->setDisabled(t);
artistObvCheckBox->setDisabled(t);
artistRevCheckBox->setDisabled(t);
engraverObvCheckBox->setDisabled(t);
engraverRevCheckBox->setDisabled(t);
issuerCheckBox->setDisabled(t);
authCheckBox->setDisabled(t);
mintageCheckBox->setDisabled(t);
obvSymbolCheckBox->setDisabled(t);
obvTypeCheckBox->setDisabled(t);
obvLegend1CheckBox->setDisabled(t);
obvLegend2CheckBox->setDisabled(t);
obvMarkCheckBox->setDisabled(t);
revSymbolCheckBox->setDisabled(t);
revTypeCheckBox->setDisabled(t);
revLegend1CheckBox->setDisabled(t);
revLegend2CheckBox->setDisabled(t);
revMarkCheckBox->setDisabled(t);
fromCheckBox->setDisabled(t);
toCheckBox->setDisabled(t);
dateObjCheckBox->setDisabled(t);
eraObjCheckBox->setDisabled(t);
rulerObjCheckBox->setDisabled(t);
regionCheckBox->setDisabled(t);
fsCheckBox->setDisabled(t);
coordCheckBox->setDisabled(t);
latitude1CheckBox->setDisabled(t);
longitude1CheckBox->setDisabled(t);
latitude2CheckBox->setDisabled(t);
longitude2CheckBox->setDisabled(t);
conditionCheckBox->setDisabled(t);
rectypeCheckBox->setDisabled(t);

    if (true == t)
    {
    nomCheckBox->setChecked(false);
    year1CheckBox->setChecked(false);
    year2CheckBox->setChecked(false);
    marksCheckBox->setChecked(false);
    stateCheckBox->setChecked(false);
    epochCheckBox->setChecked(false);
    materialCheckBox->setChecked(false);
    weightCheckBox->setChecked(false);
    estimCheckBox->setChecked(false);
    sellerCheckBox->setChecked(false);
    customerCheckBox->setChecked(false);
    dateCheckBox->setChecked(false);
    mintCheckBox->setChecked(false);
    statusCheckBox->setChecked(false);
    diamCheckBox->setChecked(false);
    edgeIDCheckBox->setChecked(false);
    typeCheckBox->setChecked(false);
    undertypeCheckBox->setChecked(false);
    edgeLegendCheckBox->setChecked(false);
    artistObvCheckBox->setChecked(false);
    artistRevCheckBox->setChecked(false);
    engraverObvCheckBox->setChecked(false);
    engraverRevCheckBox->setChecked(false);
    issuerCheckBox->setChecked(false);
    authCheckBox->setChecked(false);
    mintageCheckBox->setChecked(false);
    obvSymbolCheckBox->setChecked(false);
    obvTypeCheckBox->setChecked(false);
    obvLegend1CheckBox->setChecked(false);
    obvLegend2CheckBox->setChecked(false);
    obvMarkCheckBox->setChecked(false);
    revSymbolCheckBox->setChecked(false);
    revTypeCheckBox->setChecked(false);
    revLegend1CheckBox->setChecked(false);
    revLegend2CheckBox->setChecked(false);
    revMarkCheckBox->setChecked(false);
    fromCheckBox->setChecked(false);
    toCheckBox->setChecked(false);
    dateObjCheckBox->setChecked(false);
    eraObjCheckBox->setChecked(false);
    rulerObjCheckBox->setChecked(false);
    regionCheckBox->setChecked(false);
    fsCheckBox->setChecked(false);
    coordCheckBox->setChecked(false);
    latitude1CheckBox->setChecked(false);
    longitude1CheckBox->setChecked(false);
    latitude2CheckBox->setChecked(false);
    longitude2CheckBox->setChecked(false);
    conditionCheckBox->setChecked(false);
    rectypeCheckBox->setChecked(false);
    }
expTextEdit->setEnabled(t);
}


